package com.dgw.springbootrabbitmq.receiver;

import com.dgw.springbootrabbitmq.config.RpcConfig;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @program: spring-boot-rabbitmq
 * @description:
 * @author: Mr.Dai
 * @create: 2020-02-20 23:10
 **/
@Component
public class RpcServer {

    // 是队列的名称
    @RabbitListener(queues = RpcConfig.RPC_QUEUE_NAME)
    // 客户端不需要设置回复
    public int fibonacci(int n) {
        System.out.println(" [x] Received request for " + n);
        // 服务端指定的方法
        int result = fib(n);
        System.out.println(" [.] Returned " + result);
        return result;
    }
    // 服务端执行的方法
    public int fib(int n) {
        return n == 0 ? 0 : n == 1 ? 1 : (fib(n - 1) + fib(n - 2));
    }
}
